package refatoramento;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;

/**
 * Programa com exemplos de testes que demonstra o mesmo retorno de keys() e
 * elements() em um hashtable e em newHashMap.
 */
public class TesteExemplo {
        public static void main(String[] args) {
                Hashtable<Integer, String> h = new Hashtable<Integer, String>();
                NewHashMap<Integer, String> nh = new NewHashMap<Integer, String>();

                h.put(0, "a");
                h.put(1, "b");
                h.put(2, "c");
                h.put(3, "d");
                h.put(4, "e");
                h.put(0, "a");

                nh.put(0, "a");
                nh.put(1, "b");
                nh.put(2, "c");
                nh.put(3, "d");
                nh.put(4, "e");
                nh.put(0, "a");

                Enumeration<Integer> k = h.keys();

                Enumeration<String> e = h.elements();

                Iterator<Integer> kh = nh.keys();

                Iterator<String> eh = nh.elements();

                System.out.println("keys() de Hashtable:");
                System.out.println(k.nextElement());
                System.out.println(k.nextElement());
                System.out.println(k.nextElement());
                System.out.println(k.nextElement());
                System.out.println(k.nextElement());

                System.out.println("keys() de NewHashMap:");
                System.out.println(kh.next());
                System.out.println(kh.next());
                System.out.println(kh.next());
                System.out.println(kh.next());
                System.out.println(kh.next());

                System.out.println();

                System.out.println("elements() de Hashtable:");
                System.out.println(e.nextElement());
                System.out.println(e.nextElement());
                System.out.println(e.nextElement());
                System.out.println(e.nextElement());
                System.out.println(e.nextElement());

                System.out.println("elements() de NewHashMap:");
                System.out.println(eh.next());
                System.out.println(eh.next());
                System.out.println(eh.next());
                System.out.println(eh.next());
                System.out.println(eh.next());
        }
}